#include "Controls/TextBlock.h"
#include "cinder/gl/gl.h"

namespace cxgui
{
using namespace ci;
void TextBlock::Draw()
{
	DrawBackground();
	DrawText();
}

void TextBlock::DrawText()
{
	if(!_text.empty())
	{		
		auto textSize = GetTextSize(_text);
		auto displayRect = _clientRectangle;
		ShrinkRectangle(displayRect, _padding);
		auto center = displayRect.getCenter();
		auto fontHeight = textSize.y;
		center.y -= fontHeight * 0.5f;				
		gl::drawStringCentered(_text, center, _foreColor, _font);
	}
}

cinder::Vec2f TextBlock::GetPreferedSize()
{
	auto textSize = GetTextSize(_text);
	GrowVect(textSize, _padding);
	return textSize;
}

std::string TextBlock::GetText() const
{
	return _text;
}

void TextBlock::SetText( const string& text )
{
	if(_text != text) 
	{
		_text = text;
		OnTextChanged();
	}
}

void TextBlock::OnTextChanged()
{
	IsLayoutDirty(true);
}

TextBlock::~TextBlock()
{

}

TextBlock::TextBlock()
	: Control(), _text()
{
}

TextBlock::TextBlock( const string& text )
	: Control(), _text(text)
{

}



}